/*
 * 文件名：ParkwellMemberServiceImpl.java	 
 * 时     间：下午3:21:51
 * 作     者：Administrator       
 * 版     权： 2012-2022 湖南智软网络科技, 公司保留所有权利.
 * 联     系：http://www.073586.com/
 */
package com.local.service.impl;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Properties;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cz073586.tools.util.ThreadPoolUtil;
import com.local.common.CommonContains;
import com.local.common.PropertiesConstan;
import com.local.dao.mapers.LocalCarInRepertoryMapper;
import com.local.dao.mapers.LocalCarTypeMapper;
import com.local.dao.mapers.LocalCardMapper;
import com.local.dao.mapers.LocalChargeBytimeMapper;
import com.local.dao.mapers.LocalMemberHistoryMapper;
import com.local.dao.mapers.LocalMemberMapper;
import com.local.dao.mapers.LocalVersionMapper;
import com.local.entity.report.MemberVo;
import com.local.entity.vo.PropertiesVo;
import com.local.manager.thread.UpdateThread;
import com.local.model.LocalCarInRepertory;
import com.local.model.LocalCarInRepertoryExample;
import com.local.model.LocalCarType;
import com.local.model.LocalCard;
import com.local.model.LocalChargeBytime;
import com.local.model.LocalChargeBytimeExample;
import com.local.model.LocalMember;
import com.local.model.LocalMemberExample;
import com.local.model.LocalMemberHistory;
import com.local.page.LocalMemberPage;
import com.local.page.report.LocalMemberVoPage;
import com.local.service.face.LocalBizUpdateService;
import com.local.service.face.LocalVersionService;
import com.local.service.face.ParkwellMemberService;
import com.qianhai.common.exception.BaseException;
import com.qianhai.common.utils.Tools;
import com.qianhai.common.utils.UUIDGenerateUtil;

/**
 * 类描述:会员管理
 * 
 * @ClassName: ParkwellMemberServiceImpl
 * @author Administrator
 * @date 2015年4月5日 下午3:21:51
 */
@Service
public class ParkwellMemberServiceImpl implements ParkwellMemberService
{
	@Autowired
	private LocalMemberHistoryMapper  memberHistoryMapper;
	@Autowired
	private LocalMemberMapper parkwellMemberMapper;
	
	@Autowired
	private LocalCardMapper localCardMapper;
	
	@Autowired
	private LocalCarTypeMapper localCarTypeMapper;
	
	@Autowired
	private LocalVersionMapper localVersionMapper;
	
	@Autowired
	private LocalVersionService localVersionService;
	
	@Autowired
	private LocalBizUpdateService localBizUpdateService;
	
	@Autowired
	private LocalCarInRepertoryMapper localCarInRepertoryMapper;
	
	@Autowired
	private LocalChargeBytimeMapper localChargeBytimeMapper;
	
	@Override
	public String saveOrUpdateParkwellMember(LocalMember parkwellMember)
	{
		try
		{
			if (Tools.isEmpty(parkwellMember.getMemberUuid()))
			{
				if (Tools.isEmpty(parkwellMember.getMemberName()))
				{
					throw new BaseException("15000-00000-00019");
				}
				if (Tools.isEmpty(parkwellMember.getCarNo()))
				{
					throw new BaseException("15000-00000-00020");
				}
				if (!Tools.isEmpty(parkwellMemberMapper
						.findParkwellMemberByCarNo(parkwellMember.getCarNo())))
				{
					throw new BaseException("15000-00000-00021");
				}
				if(Tools.isEmpty(parkwellMember.getMoney())){
					throw new BaseException("15000-00000-00027");
				}
				parkwellMember.setMemberUuid(UUIDGenerateUtil.generate());
				parkwellMember.setCreateTime(new Date(System
						.currentTimeMillis()));
				LocalCard newCard = localCardMapper
						.selectByPrimaryKey(parkwellMember.getCardUuid());
				if (Tools.isEmpty(parkwellMember.getBegainTime()))
				{
					parkwellMember.setStartTime(new Date(System
							.currentTimeMillis()));
				} else
				{
					SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
					Date date = null;
					date = format.parse(parkwellMember.getBegainTime());
					parkwellMember.setStartTime(date);
				}
				// 获取总体时间
				Date no = new Date(parkwellMember.getStartTime().getTime()
						+ Long.valueOf(newCard.getCardTime()) * 24 * 3600000);
				// 追加结束时间，并转String
				SimpleDateFormat la = new SimpleDateFormat(
						"yyyy-MM-dd 23:59:59");
				String vv = la.format(no);
				// 转换为Date类型
				SimpleDateFormat hh = new SimpleDateFormat(
						"yyyy-MM-dd HH:mm:ss");
				Date tt = hh.parse(vv);
				parkwellMember.setAttr1(hh.format(new Date(System
						.currentTimeMillis())));
				parkwellMember.setEndTime(tt);
				parkwellMember
						.setVersion(localVersionService
								.selectLocalVersionByVersionType(CommonContains.VERSION_MEMBER));
				parkwellMember.setOperate(1);
				parkwellMember.setAttr3(parkwellMember.getCarNo());
				parkwellMemberMapper.insert(parkwellMember);
				LocalMemberHistory memberHistory=new LocalMemberHistory();
				//新建
				memberHistory.setState("create");			
				BeanUtils.copyProperties(memberHistory, parkwellMember);
				memberHistory.setUuid(UUIDGenerateUtil.generate());
				memberHistoryMapper.insert(memberHistory);
				UpdateThread updateThread = new UpdateThread(
						localBizUpdateService, CommonContains.TABLE_MEMBER,
						parkwellMember.getMemberUuid(), parkwellMember);
				ThreadPoolUtil.instance().execute(updateThread);
			} else
			{
				if (Tools.isEmpty(parkwellMember.getMemberName()))
				{
					throw new BaseException("15000-00000-00019");
				}
				if (Tools.isEmpty(parkwellMember.getCarNo()))
				{
					throw new BaseException("15000-00000-00020");
				}
				if(Tools.isEmpty(parkwellMember.getMoney())){
					throw new BaseException("15000-00000-00027");
				}
				LocalMember localMemberOld = parkwellMemberMapper
						.selectByPrimaryKey(parkwellMember.getMemberUuid());
				if (!localMemberOld.getCarNo().equalsIgnoreCase(
						parkwellMember.getCarNo()))
				{
					if (!Tools.isEmpty(parkwellMemberMapper
							.findParkwellMemberByCarNo(parkwellMember
									.getCarNo())))
					{
						throw new BaseException("15000-00000-00021");
					}
				}
				LocalCard newCard = localCardMapper
						.selectByPrimaryKey(parkwellMember.getCardUuid());
				if (Tools.isEmpty(parkwellMember.getBegainTime()))
				{
					parkwellMember.setStartTime(new Date(System
							.currentTimeMillis()));
				} else
				{
					SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
					Date date = null;
					date = format.parse(parkwellMember.getBegainTime());
					parkwellMember.setStartTime(date);
				}
				SimpleDateFormat dd = new SimpleDateFormat(
						"yyyy-MM-dd hh:mm:ss");
				parkwellMember.setAttr1(dd.format(new Date(System
						.currentTimeMillis())));
				parkwellMember.setEndTime(parkwellMember.getEndTime());
				parkwellMember.setCreateTime(localMemberOld.getCreateTime());
				// 设置为充值状态。。云平台默认，为修改状态
				parkwellMember.setOperate(8);
				parkwellMemberMapper.updateByPrimaryKey(parkwellMember);
				
				LocalMemberHistory memberHistory=new LocalMemberHistory();
				BeanUtils.copyProperties(memberHistory, parkwellMember);
				
				memberHistory.setState("update");
				memberHistory.setUuid(UUIDGenerateUtil.generate());
				memberHistoryMapper.insertSelective(memberHistory);
				
			}
			LocalCarInRepertoryExample carInEx = new LocalCarInRepertoryExample();
			carInEx.or().andCarNoEqualTo(parkwellMember.getCarNo().trim());
			List<LocalCarInRepertory> localCarInRepertories = localCarInRepertoryMapper
					.selectByCondition(carInEx);
			if (!Tools.isEmpty(localCarInRepertories))
			{
				for (LocalCarInRepertory carInRepertory : localCarInRepertories)
				{
					if (!Tools.isEmpty(carInRepertory))
					{
						if (carInRepertory.getCarInTime().after(
								parkwellMember.getStartTime())
								&& carInRepertory.getCarInTime().before(
										parkwellMember.getEndTime()))
						{
							LocalChargeBytimeExample dd=new LocalChargeBytimeExample();
							dd.or().andAttr4EqualTo("100");
							List<LocalChargeBytime> charLis=localChargeBytimeMapper.selectByCondition(dd);
							carInRepertory.setChargeUuid(!Tools.isEmpty(charLis)&&charLis.size()>0?charLis.get(0).getChargeBytimeUuid():null);
							carInRepertory.setAttr("100");
						}
						carInRepertory.setExpireTime(parkwellMember
								.getEndTime());
						carInRepertory.setStartTime(parkwellMember
								.getStartTime());
						carInRepertory
								.setOpenType(CommonContains.OPEN_TYPE_TRUE);
						carInRepertory.setPayType(CommonContains.MEMBER_LIST);
						localCarInRepertoryMapper
								.updateByPrimaryKeySelective(carInRepertory);
						
						
					}
				}
			}
		} catch (Throwable e)
		{
			e.printStackTrace();
			throw new BaseException(e.getMessage());
		}
		return parkwellMember.getMemberUuid();
	}
	
	@Override
	public List<LocalMember> findAllParkwellMemberByQueryForm(
			LocalMemberPage<LocalMember> pageInfo)
	{
		Integer recordCount = parkwellMemberMapper.countAllByPage(pageInfo);
		pageInfo.setTotalRecords(recordCount);
		List<LocalMember> list = parkwellMemberMapper.queryByPage(pageInfo);
		if (!Tools.isEmpty(list) && list.size() > 0)
		{
			for (LocalMember li : list)
			{
				li.setEffective("过期");
				Date now = new Date(System.currentTimeMillis());
				if (!Tools.isEmpty(li.getEndTime())
						&& !Tools.isEmpty(li.getStartTime()))
				{
					if (now.before(li.getEndTime())
							&& now.after(li.getStartTime()))
					{
						li.setEffective("有效");
					}
				}
			}
		}
		pageInfo.setData(list);
		return list;
	}
	
	@Override
	public Boolean deleteByPrimaryKey(String memberUuid)
	{
		try
		{
			parkwellMemberMapper.deleteByPrimaryKey(memberUuid);
			return true;
		} catch (Throwable e)
		{
			return false;
		}
	}
	
	@Override
	public List<LocalMember> findParkwellMemberByCarNo(String carNo)
	{
		return parkwellMemberMapper.findParkwellMemberByCarNo(carNo);
	}
	
	@Override
	public List<LocalMember> findCarNoIsMemberInPark(String carNo,
			Date happenTime)
	{
		return parkwellMemberMapper.findCarNoIsMemberInPark(carNo, happenTime);
	}
	
	@Override
	public Object selectByPrimaryKey(String memberUuid)
	{
		return parkwellMemberMapper.selectByPrimaryKey(memberUuid);
	}
	
	@Override
	public List<LocalCard> queryAllCard()
	{
		// TODO Auto-generated method stub
		List<LocalCard> li = localCardMapper.queryAllCard();
		return li;
	}
	
	@Override
	public List<LocalCarType> queryAllCar()
	{
		// TODO Auto-generated method stub
		List<LocalCarType> li = localCarTypeMapper.queryAllCarType();
		return li;
	}
	
	@Override
	public void deleteOtherMember(String carNo)
	{
		// TODO Auto-generated method stub
		LocalMemberExample condtion = new LocalMemberExample();
		condtion.or().andCarNoEqualTo(carNo);
		parkwellMemberMapper.deleteByCondition(condtion);
	}
	
	@Override
	public String saveOrUpdateOtherMember(LocalMember parkwellMember)
	{
		// TODO Auto-generated method stub
		try
		{
			// 接口信息转换 位 本地封装实体
			parkwellMember = returnOtherMemberCar(parkwellMember);
			
			// 查询当前车辆，是否已经存在与会员信息中
			List<LocalMember> lm = parkwellMemberMapper
					.findParkwellMemberByCarNo(parkwellMember.getCarNo());
			if (!Tools.isEmpty(lm) && lm.size() > 1)
			{
				LocalMemberExample cond = new LocalMemberExample();
				cond.or().andCarNoEqualTo(parkwellMember.getCarNo());
				parkwellMemberMapper.deleteByCondition(cond);
			}
			
			if (!Tools.isEmpty(parkwellMember.getOperate()))
			{
				switch (parkwellMember.getOperate())
				{
				case 1:
					parkwellMember.setMemberUuid(UUIDGenerateUtil.generate());
					parkwellMemberMapper.insertSelective(parkwellMember);
					break;
				case 5:
					// 通过车牌号，删除会员车主信息
					deleteOtherMember(parkwellMember.getCarNo());
					break;
				case 8:
					List<LocalMember> lmm = parkwellMemberMapper
							.findParkwellMemberByCarNo(parkwellMember
									.getCarNo());
					if (!Tools.isEmpty(lmm))
					{
						deleteOtherMember(parkwellMember.getCarNo());
					}
					StringBuilder oldCarNo = new StringBuilder(
							parkwellMember.getCarNo());
					parkwellMember.setMemberUuid(UUIDGenerateUtil.generate());
					parkwellMember.setCarNo(!Tools.isEmpty(parkwellMember
							.getNewCarNo()) ? parkwellMember.getNewCarNo()
							: parkwellMember.getCarNo());
					parkwellMember.setNewCarNo(oldCarNo.toString());
					parkwellMemberMapper.insertSelective(parkwellMember);
					break;
				default:
					// 其他的，为修改信息
					if (!Tools.isEmpty(lm))
					{
						parkwellMember.setMemberUuid(lm.get(0).getMemberUuid());
						parkwellMemberMapper
								.updateByPrimaryKeySelective(parkwellMember);
					}
					break;
				}
			}
		} catch (Throwable e)
		{
			throw new BaseException(e.getMessage());
		}
		return parkwellMember.getMemberUuid();
	}
	
	// 接口转换位 会员车主信息
	public LocalMember returnOtherMemberCar(LocalMember parkwellMember)
	{
		LocalMember lm = new LocalMember();
		try
		{
			if (!Tools.isEmpty(parkwellMember))
			{
				lm.setCarNo(!Tools.isEmpty(parkwellMember.getCarNo()) ? parkwellMember
						.getCarNo() : "无车牌");
				lm.setMemberName(!Tools.isEmpty(parkwellMember.getMemberName()) ? parkwellMember
						.getMemberName() : "无车主");
				lm.setOperate(!Tools.isEmpty(parkwellMember.getOperate()) ? parkwellMember
						.getOperate() : 1);
				lm.setTelephone(!Tools.isEmpty(parkwellMember.getTelephone()) ? parkwellMember
						.getTelephone() : "123");
				lm.setCompany(!Tools.isEmpty(parkwellMember.getCompany()) ? parkwellMember
						.getCompany() : "123");
				lm.setCarType(!Tools.isEmpty(parkwellMember.getCarType()) ? parkwellMember
						.getCarType() : 11);
				lm.setRemark(!Tools.isEmpty(parkwellMember.getRemark()) ? parkwellMember
						.getRemark() : "无信息");
				lm.setCreateTime(!Tools.isEmpty(parkwellMember.getCreateTime()) ? parkwellMember
						.getCreateTime() : new Date());
				lm.setStartTime(!Tools.isEmpty(parkwellMember.getStartTime()) ? parkwellMember
						.getStartTime() : new Date());
				lm.setEndTime(!Tools.isEmpty(parkwellMember.getEndTime()) ? parkwellMember
						.getEndTime() : new Date());
				if (11 <= lm.getCarType() && lm.getCarType() <= 14)
				{
					SimpleDateFormat dd = new SimpleDateFormat("yyyy-MM-dd");
					String statr = "2016-01-01";
					String end = "2016-01-02";
					lm.setStartTime(dd.parse(statr));
					lm.setEndTime(dd.parse(end));
				}
				lm.setNewCarNo(!Tools.isEmpty(parkwellMember.getNewCarNo()) ? parkwellMember
						.getNewCarNo() : parkwellMember.getCarNo());
				
				lm.setVersion(localVersionService
						.selectLocalVersionByVersionType(CommonContains.VERSION_MEMBER));
			}
		} catch (Exception e)
		{
			// TODO: handle exception
		}
		return lm;
	}
	
	@Override
	public PropertiesVo localProperties(String typeProperties)
	{
		// TODO Auto-generated method stub
		return compType(typeProperties);
	}
	
	public PropertiesVo compType(String typeProperties)
	{
		PropertiesVo pv = new PropertiesVo();
		Properties prop = new Properties();
		String filePath = "";
		switch (typeProperties)
		{
		// 云端下发配置
		case PropertiesConstan.MESSAGE_PROPERTIES:
			filePath = ParkwellMemberServiceImpl.class.getClassLoader()
					.getResource(PropertiesConstan.MESSAGE_PROPERTIES)
					.getPath();
			try
			{
				InputStream fis = new FileInputStream(filePath);
				// 从输入流中读取属性列表（键和元素对）
				prop.load(fis);
				// 输入云端 地址
				pv.setServer_host(prop.getProperty("server_host"));
				// 云端端口号
				pv.setServer_port(prop.getProperty("server_port"));
				// 与socket通信协议
				pv.setSocket_encoding(prop.getProperty("socket_encoding"));
				// 中间件唯一标记
				pv.setIndicate(prop.getProperty("Indicate"));
				fis.close();
			} catch (IOException e)
			{
				System.err.println("Visit " + filePath + " for updating "
						+ "ddd" + " value error");
			}
			break;
		// 本地上传配置
		case PropertiesConstan.CLOUDCFG_PROPERTIES:
			filePath = ParkwellMemberServiceImpl.class.getClassLoader()
					.getResource(PropertiesConstan.CLOUDCFG_PROPERTIES)
					.getPath();
			try
			{
				InputStream fis = new FileInputStream(filePath);
				// 从输入流中读取属性列表（键和元素对）
				prop.load(fis);
				pv.setIs_open(prop.getProperty("is_open"));// 本地上传云是否开启 true
				// 本地上传云中间件编号
				pv.setExchange_id(prop.getProperty("exchange_id"));
				// 本地上传云连接地址
				pv.setProtocol(prop.getProperty("protocol"));
				pv.setHost(prop.getProperty("host"));
				pv.setPort(prop.getProperty("port"));
				fis.close();
			} catch (IOException e)
			{
				System.err.println("Visit " + filePath + " for updating "
						+ "ddd" + " value error");
			}
			break;
		// 相机与流媒体
		case PropertiesConstan.MEDIACFG_PROPERTIES:
			filePath = ParkwellMemberServiceImpl.class.getClassLoader()
					.getResource(PropertiesConstan.MEDIACFG_PROPERTIES)
					.getPath();
			try
			{
				InputStream fis = new FileInputStream(filePath);
				// 从输入流中读取属性列表（键和元素对）
				prop.load(fis);
				pv.setMedia_server_host(prop.getProperty("media_server_host"));// 相机与流媒体
																				// 127.0.0.1
				pv.setMedia_server_port(prop.getProperty("media_server_port"));// 流媒体端口号
																				// 1935
				pv.setMedia_server_protocol(prop
						.getProperty("media_server_protocol"));// 流媒体服务器协议 rtmp
				pv.setMedia_server_stream(prop
						.getProperty("media_server_stream"));// #流媒体服务器流,如房间号
																// live
				pv.setEquipment_protocol(prop.getProperty("equipment_protocol"));// 相机协议配置
																					// rtsp
				pv.setEquipment_port(prop.getProperty("equipment_port")); // 50000
				pv.setEquipment_stream(prop.getProperty("equipment_stream")); // video
				pv.setEquipment_resolution(prop
						.getProperty("equipment_resolution"));// 1280X720
				fis.close();
			} catch (IOException e)
			{
				System.err.println("Visit " + filePath + " for updating "
						+ "ddd" + " value error");
			}
			break;
		// 中间件下发开闸配置
		case PropertiesConstan.MIDDLEWARE_PROPERTIES:
			filePath = ParkwellMemberServiceImpl.class.getClassLoader()
					.getResource(PropertiesConstan.MIDDLEWARE_PROPERTIES)
					.getPath();
			try
			{
				InputStream fis = new FileInputStream(filePath);
				// 从输入流中读取属性列表（键和元素对）
				prop.load(fis);
				pv.setMiddleware_ip(prop.getProperty("middleware_ip"));// #中间配置，下发开闸指令192.168.2.7
				pv.setMiddleware_port(prop.getProperty("middleware_port"));// #中间件端口
																			// 60000
				pv.setEncoding(prop.getProperty("encoding"));// #编码格式 utf-8
				pv.setTime_out(prop.getProperty("time_out"));// #超时时间 1 表示 10秒 2
																// 表示20秒 1
				fis.close();
			} catch (IOException e)
			{
				System.err.println("Visit " + filePath + " for updating "
						+ "ddd" + " value error");
			}
			break;
		// 上报车辆信息配置
		case PropertiesConstan.REPORTCLOUDCFG_PROPERTIES:
			filePath = ParkwellMemberServiceImpl.class.getClassLoader()
					.getResource(PropertiesConstan.REPORTCLOUDCFG_PROPERTIES)
					.getPath();
			try
			{
				InputStream fis = new FileInputStream(filePath);
				// 从输入流中读取属性列表（键和元素对）
				prop.load(fis);
				pv.setIs_open(prop.getProperty("is_open"));// 本地上传云是否开启 false
				pv.setProtocol(prop.getProperty("protocol"));
				pv.setHost(prop.getProperty("host"));
				pv.setPort(prop.getProperty("port"));
				pv.setReportCarInfo(prop.getProperty("reportCarInfo"));// 上传到交警地址pushCarInfo
				fis.close();
			} catch (IOException e)
			{
				System.err.println("Visit " + filePath + " for updating "
						+ "ddd" + " value error");
			}
			break;
		default:
			break;
		}
		return pv;
	}
	
	@Override
	public void updateProperties(PropertiesVo pv)
	{
		// TODO Auto-generated method stub
		Properties prop = new Properties();
		String filePath = "";
		if (!Tools.isEmpty(pv))
		{
			switch (pv.getType())
			{
			// 云端下发配置
			case PropertiesConstan.MESSAGE_PROPERTIES:
				filePath = ParkwellMemberServiceImpl.class.getClassLoader()
						.getResource(PropertiesConstan.MESSAGE_PROPERTIES)
						.getPath();
				try
				{
					InputStream fis = new FileInputStream(filePath);
					// 从输入流中读取属性列表（键和元素对）
					prop.load(fis);
					OutputStream fos = new FileOutputStream(filePath);
					if (!Tools.isEmpty(pv.getServer_host()))
					{
						prop.setProperty("server_host", pv.getServer_host());
					}
					if (!Tools.isEmpty(pv.getServer_port()))
					{
						prop.setProperty("server_port", pv.getServer_port());
					}
					if (!Tools.isEmpty(pv.getIndicate()))
					{
						prop.setProperty("Indicate", pv.getIndicate());
					}
					if (!Tools.isEmpty(pv.getSocket_encoding()))
					{
						prop.setProperty("socket_encoding",
								pv.getSocket_encoding());
					}
					prop.store(fos, null);
					fis.close();
					fos.close();
				} catch (IOException e)
				{
					System.err.println("Visit " + filePath + " for updating "
							+ "ddd" + " value error");
				}
				break;
			// 本地上传配置
			case PropertiesConstan.CLOUDCFG_PROPERTIES:
				filePath = ParkwellMemberServiceImpl.class.getClassLoader()
						.getResource(PropertiesConstan.CLOUDCFG_PROPERTIES)
						.getPath();
				try
				{
					InputStream fis = new FileInputStream(filePath);
					// 从输入流中读取属性列表（键和元素对）
					prop.load(fis);
					OutputStream fos = new FileOutputStream(filePath);
					if (!Tools.isEmpty(pv.getIs_open()))
					{
						prop.setProperty("is_open", pv.getIs_open());
					}
					if (!Tools.isEmpty(pv.getExchange_id()))
					{
						prop.setProperty("exchange_id", pv.getExchange_id());
					}
					if (!Tools.isEmpty(pv.getProtocol()))
					{
						prop.setProperty("protocol", pv.getProtocol());
					}
					if (!Tools.isEmpty(pv.getHost()))
					{
						prop.setProperty("host", pv.getHost());
					}
					if (!Tools.isEmpty(pv.getPort()))
					{
						prop.setProperty("port", pv.getPort());
					}
					prop.store(fos, null);
					fis.close();
					fos.close();
				} catch (IOException e)
				{
					System.err.println("Visit " + filePath + " for updating "
							+ "ddd" + " value error");
				}
				break;
			// 相机与流媒体
			case PropertiesConstan.MEDIACFG_PROPERTIES:
				filePath = ParkwellMemberServiceImpl.class.getClassLoader()
						.getResource(PropertiesConstan.MEDIACFG_PROPERTIES)
						.getPath();
				try
				{
					InputStream fis = new FileInputStream(filePath);
					// 从输入流中读取属性列表（键和元素对）
					prop.load(fis);
					OutputStream fos = new FileOutputStream(filePath);
					if (!Tools.isEmpty(pv.getMedia_server_host()))
					{
						prop.setProperty("media_server_host",
								pv.getMedia_server_host());
					}
					if (!Tools.isEmpty(pv.getMedia_server_port()))
					{
						prop.setProperty("media_server_port",
								pv.getMedia_server_port());
					}
					if (!Tools.isEmpty(pv.getMedia_server_protocol()))
					{
						prop.setProperty("media_server_protocol",
								pv.getMedia_server_protocol());
					}
					if (!Tools.isEmpty(pv.getMedia_server_stream()))
					{
						prop.setProperty("media_server_stream",
								pv.getMedia_server_stream());
					}
					if (!Tools.isEmpty(pv.getEquipment_protocol()))
					{
						prop.setProperty("equipment_protocol",
								pv.getEquipment_protocol());
					}
					if (!Tools.isEmpty(pv.getEquipment_port()))
					{
						prop.setProperty("equipment_port",
								pv.getEquipment_port());
					}
					if (!Tools.isEmpty(pv.getEquipment_stream()))
					{
						prop.setProperty("equipment_stream",
								pv.getEquipment_stream());
					}
					if (!Tools.isEmpty(pv.getEquipment_resolution()))
					{
						prop.setProperty("equipment_resolution",
								pv.getEquipment_resolution());
					}
					prop.store(fos, null);
					fis.close();
					fos.close();
				} catch (IOException e)
				{
					System.err.println("Visit " + filePath + " for updating "
							+ "ddd" + " value error");
				}
				break;
			// 中间件下发开闸配置
			case PropertiesConstan.MIDDLEWARE_PROPERTIES:
				filePath = ParkwellMemberServiceImpl.class.getClassLoader()
						.getResource(PropertiesConstan.MIDDLEWARE_PROPERTIES)
						.getPath();
				try
				{
					InputStream fis = new FileInputStream(filePath);
					// 从输入流中读取属性列表（键和元素对）
					prop.load(fis);
					OutputStream fos = new FileOutputStream(filePath);
					if (!Tools.isEmpty(pv.getMiddleware_ip()))
					{
						prop.setProperty("middleware_ip", pv.getMiddleware_ip());
					}
					if (!Tools.isEmpty(pv.getMiddleware_port()))
					{
						prop.setProperty("middleware_port",
								pv.getMiddleware_port());
					}
					if (!Tools.isEmpty(pv.getEncoding()))
					{
						prop.setProperty("encoding", pv.getEncoding());
					}
					if (!Tools.isEmpty(pv.getTime_out()))
					{
						prop.setProperty("time_out", pv.getTime_out());
					}
					prop.store(fos, null);
					fis.close();
					fos.close();
				} catch (IOException e)
				{
					System.err.println("Visit " + filePath + " for updating "
							+ "ddd" + " value error");
				}
				break;
			// 上报车辆信息配置
			case PropertiesConstan.REPORTCLOUDCFG_PROPERTIES:
				filePath = ParkwellMemberServiceImpl.class
						.getClassLoader()
						.getResource(
								PropertiesConstan.REPORTCLOUDCFG_PROPERTIES)
						.getPath();
				try
				{
					InputStream fis = new FileInputStream(filePath);
					// 从输入流中读取属性列表（键和元素对）
					prop.load(fis);
					OutputStream fos = new FileOutputStream(filePath);
					if (!Tools.isEmpty(pv.getIs_open()))
					{
						prop.setProperty("is_open", pv.getIs_open());
					}
					if (!Tools.isEmpty(pv.getProtocol()))
					{
						prop.setProperty("protocol", pv.getProtocol());
					}
					if (!Tools.isEmpty(pv.getHost()))
					{
						prop.setProperty("host", pv.getHost());
					}
					if (!Tools.isEmpty(pv.getPort()))
					{
						prop.setProperty("port", pv.getPort());
					}
					if (!Tools.isEmpty(pv.getReportCarInfo()))
					{
						prop.setProperty("reportCarInfo", pv.getReportCarInfo());
					}
					prop.store(fos, null);
					fis.close();
					fos.close();
				} catch (IOException e)
				{
					System.err.println("Visit " + filePath + " for updating "
							+ "ddd" + " value error");
				}
				break;
			default:
				break;
			}
		}
	}
	
	@Override
	public Date countCarOutTime(Date carInTime, Date localMemberStartTime)
	{
		try
		{
			if (carInTime.getTime() < localMemberStartTime.getTime())
			{
				Long timeCha = localMemberStartTime.getTime()
						- carInTime.getTime();
				Date c = new Date(carInTime.getTime() + timeCha);
				return c;
			}
		} catch (Exception e)
		{
			return null;
		}
		return null;
	}
	
	@Override
	public MemberVo queryMemberReport(LocalMemberVoPage<MemberVo> pageInfo) {
		// TODO Auto-generated method stub
		MemberVo mv=parkwellMemberMapper.queryMemberVo(pageInfo);
		return mv;
	}

	@Override
	public List<LocalMember> queryMemberReportDetails(LocalMemberPage<LocalMember> pageInfo) {
		// TODO Auto-generated method stub
		Integer recordCount = parkwellMemberMapper.countAllByVoPage(pageInfo);
		pageInfo.setTotalRecords(recordCount);
		List<LocalMember> list = parkwellMemberMapper.queryByVoPage(pageInfo);
		if (!Tools.isEmpty(list) && list.size() > 0)
		{
			for (LocalMember li : list)
			{
				li.setEffective("过期");
				Date now = new Date(System.currentTimeMillis());
				if (!Tools.isEmpty(li.getEndTime())
						&& !Tools.isEmpty(li.getStartTime()))
				{
					if (now.before(li.getEndTime())
							&& now.after(li.getStartTime()))
					{
						li.setEffective("有效");
					}
				}
			}
		}
		pageInfo.setData(list);
		return list;
	}
}
